//
//  DetailListCell.m
//  SeeFood
//
//  Created by 陈伟捷 on 15/11/24.
//  Copyright © 2015年 纪洪波. All rights reserved.
//

#import "DetailListCell.h"
#import "UIImageView+WebCache.h"

#define KScreenWidth [[UIScreen mainScreen] bounds].size.width
#define KScreenHeight [[UIScreen mainScreen] bounds].size.height

@interface DetailListCell ()
{
    CGFloat height;
}

@end
@implementation DetailListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 不可选中
        self.selected = NO;
        
        height = KScreenWidth * 2 / 3;
        
        _myImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, height)];
        self.myImageView.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:_myImageView];
        
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height, KScreenWidth - 20, 30)];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.font = [UIFont systemFontOfSize:17];
        [self.contentView addSubview:_titleLabel];
        
        _synopsisLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 30, KScreenWidth - 20, 30)];
        _synopsisLabel.font = [UIFont systemFontOfSize:13];
        _synopsisLabel.numberOfLines = 0;
        [self.contentView addSubview:_synopsisLabel];
    }
    return self;
}

- (void)setModel:(DetailListModel *)model
{
    // 动态返回简洁的高度
    CGRect bounds = [model.imtro boundingRectWithSize:CGSizeMake(KScreenWidth - 20                                                                                                                                                                                                                                                                                                                                                                                            , 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} context:nil];
    _synopsisLabel.frame = CGRectMake(10, height + 30, KScreenWidth - 20, bounds.size.height);
    
    // 请求照片
    NSString *string = [model.albums firstObject];
    [self.myImageView sd_setImageWithURL:[NSURL URLWithString:string]];
    
    self.titleLabel.text = model.title;
    
    self.synopsisLabel.text = model.imtro;
}

+ (CGFloat)rowHeight:(DetailListModel *)model
{
    CGRect bounds = [model.imtro boundingRectWithSize:CGSizeMake(KScreenWidth - 20, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} context:nil];
    return bounds.size.height + KScreenWidth * 2 / 3 + 30 + 10;
}

@end
